package com.iknow.util;

public abstract class Dynamics
{
  private static final int MAX_TIMESTEP = 50;
  protected long mLastTime;
  protected float mMaxPosition = 3.4028235e+38F;
  protected float mMinPosition = -340282346638528860000000000000000000000.0F;
  protected float mPosition;
  protected float mVelocity;

  public Dynamics()
  {
    this.mLastTime = 0L;
  }

  protected float getDistanceToLimit()
  {
    float f = 0F;
    if (this.mPosition > this.mMaxPosition)
      f = this.mMaxPosition - this.mPosition;
    while (true)
    {
      do
        return f;
      while (this.mPosition >= this.mMinPosition);
      f = this.mMinPosition - this.mPosition;
    }
  }

  public float getPosition()
  {
    return this.mPosition;
  }

  public float getVelocity()
  {
    return this.mVelocity;
  }

  public boolean isAtRest(float paramFloat1, float paramFloat2)
  {
    int i;
    int j;
    int k;
    if (Math.abs(this.mVelocity) < paramFloat1)
    {
      i = 1;
      if ((this.mPosition - paramFloat2 >= this.mMaxPosition) || (paramFloat2 + this.mPosition <= this.mMinPosition))
        break label65;
      j = 1;
      if ((i == 0) || (j == 0))
        break label71;
      k = 1;
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          return k;
          i = 0;
        }
        label65: j = 0;
      }
      label71: k = 0;
    }
  }

  protected abstract void onUpdate(int paramInt);

  public void setMaxPosition(float paramFloat)
  {
    this.mMaxPosition = paramFloat;
  }

  public void setMinPosition(float paramFloat)
  {
    this.mMinPosition = paramFloat;
  }

  public void setState(float paramFloat1, float paramFloat2, long paramLong)
  {
    this.mVelocity = paramFloat2;
    this.mPosition = paramFloat1;
    this.mLastTime = paramLong;
  }

  public void update(long paramLong)
  {
    int i = (int)(paramLong - this.mLastTime);
    if (i > 50)
      i = 50;
    onUpdate(i);
    this.mLastTime = paramLong;
  }
}